<template>
  <PageWrapper title="" contentBackground content="" contentClass="p-4">
    <div></div>
  </PageWrapper>
</template>
<script lang="ts">
  import { BasicForm } from '/@/components/Form';
  import { defineComponent, computed, onMounted } from 'vue';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { PageWrapper } from '/@/components/Page';
  import { useGo } from '/@/hooks/web/usePage';
  import { Card } from 'ant-design-vue';
  import WebOfficeSDK from '/@/utils/webOffice/web-office-sdk-solution-v2.0.5.es.js';
  import { useRouter } from 'vue-router';
  import { useUserStore } from '/@/store/modules/user';
  import { getWebOfficeFileId } from '/@/api/process/process';

  export default defineComponent({
    name: 'WebOffice',
    components: { BasicForm, PageWrapper, Card },
    setup() {
      const { createMessage } = useMessage();
      const go = useGo();
      const { currentRoute, replace, push, resolve } = useRouter();
      const userStore = useUserStore();

      console.log('currentRoute', currentRoute.value);

      onMounted(async () => {
        let type = currentRoute.value?.query?.type;
        let id = currentRoute.value?.query?.id;
        let actionId = currentRoute.value?.query?.actionId;
        let mode = currentRoute.value?.query?.mode;
        let moduleCode = currentRoute.value?.query?.moduleCode;
        let token = currentRoute.value?.query?.token;
        let data = await getWebOfficeFileId({ type, id, actionId, mode, moduleCode });
        // let fileId;
        // if (type == 'flow') {
        //   fileId = type + '_' + actionId + '_' + mode + '_' + id;
        // } else {
        //   fileId = type + '_' + moduleCode + '_' + mode + '_' + id;
        // }
        console.log('data', data, 'token', token);

        let ext = currentRoute.value?.query.ext;
        let officeType;
        if (ext == 'doc' || ext == 'docx') {
          officeType = WebOfficeSDK.OfficeType.Writer;
        } else if (ext == 'xls' || ext == 'xlsx') {
          officeType = WebOfficeSDK.OfficeType.Spreadsheet;
        } else if (ext == 'ppt' || ext == 'pptx') {
          officeType = WebOfficeSDK.OfficeType.Presentation;
        } else if (ext == 'pdf') {
          officeType = WebOfficeSDK.OfficeType.Pdf;
        } else {
          console.error('文件类型: ' + ext + '非法');
        }

        WebOfficeSDK.init({
          officeType: officeType,
          appId: userStore.serverInfo.webOfficeAppId, // 'SX20240509BAOVXL',
          fileToken: token,
          fileId: data.fileId,
          mode: mode == 'w' ? 'normal' : 'simple',
          // mount: document.querySelector('#webOffice'),
          // 通用选项，所有类型文档适用
          commonOptions: {
            isShowTopArea: true, // 隐藏顶部区域（头部和工具栏）
            isShowHeader: true, // 隐藏头部区域
            isBrowserViewFullscreen: false, // 是否在浏览器区域全屏
            isIframeViewFullscreen: false, // 是否在 iframe 区域内全屏
            acceptVisualViewportResizeEvent: true, // 控制 WebOffice 是否接受外部的 VisualViewport
          },
        });
      });

      return {};
    },
  });
</script>
<style lang="less" scoped>
  .form-wrap {
    padding: 24px;
    background-color: @component-background;
  }
</style>
